//导入模块
var express = require("express")
var path = require("path")
var cookieParser = require("cookie-parser")
var logger = require("morgan")
//导入require-directory模块
const AutoDir = require("require-directory")
//导入解决跨域模块
const cors = require("cors")
//配置函数
function initManage(app) {
  //注册插件
  app.use(logger("dev"))
  app.use(express.json())
  app.use(express.urlencoded({ extended: false }))
  app.use(cookieParser())
  app.use(express.static(path.join(__dirname, "public")))
  //注册cors
  app.use(cors())
  const useRoutes = (obj) => {
    if (obj.stack) {
      app.use(obj)
    }
  }
  AutoDir(module, "../routes", { visit: useRoutes })
}
module.exports = initManage
